﻿<%--
  Created by IntelliJ IDEA.
  User: bb
  Date: 2021/10/17
  Time: 20:08
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <%--不缓存--%>
    <%--<META HTTP-EQUIV="refresh" CONTENT="1">--%>

    <title>Title</title>
    <link href="jquery-easyui-1.7.0/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="jquery-easyui-1.7.0/themes/icon.css" rel="stylesheet" type="text/css" />
    <link href="jquery-easyui-1.7.0/demo/demo.css" rel="stylesheet" type="text/css" />
    <script src="jquery-easyui-1.7.0/jquery.min.js" type="text/javascript"></script>
    <script src="jquery-easyui-1.7.0/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="jquery-easyui-1.7.0/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
</head>
<body>
    <table id="datagrid_type" class="easyui-datagrid"></table>
    <%--查询工具栏--%>
    <div id="searchBar1" style="padding: 2px 5px;">
      <form id="searchForm" method="post">
          <div style="padding: 3px">
              类型名称：<input class="easyui-textbox" id="name" name="name" style="width: 110px" value="请输入关键字..."/>
              <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="searchType();">查找</a>
          </div>
      </form>
    </div>
    <%--操作工具栏--%>
    <div id="toolbar" style="padding: 2px 5px;">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="addType1();">添加</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editProduct1();">修改</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" plain="true" onclick="removeProduct1();">删除</a>
    </div>
    <%--dialog--%>
    <div id="dialog_type" class="easyui-dialog" title="添加商品" closed="true" style="width: 500px">
        <div style="padding: 10px 60px 20px 60px">
            <form id="dialog_form" method="post" action="" >
                <table cellpadding="5">
                    <tr>
                        <td>新商品类型：</td>
                        <td>
                            <input type="text" id="newTypeName" name="name" data-options="required:true"/>
                        </td>
                    </tr>
                </table>
                <div style="text-align: center; padding: 5px;">
                    <a class="easyui-linkbutton" href="javascript:void(0)" onclick="saveType();">保存</a>
                    <a class="easyui-linkbutton" href="javascript:void(0)" onclick="clearForm();">清空</a>
                </div>
            </form>
        </div>
    </div>

    <script>
        $(function (){
            $('#datagrid_type').datagrid({
                singleSelect:true,//设置为单选
                rownumbers:true,//显示行号
                fit:true,//自适应
                fitColumns:true,
                header:'#searchBar1',//为datagrid添加搜索栏
                toolbar:'#toolbar',//为datagrid添加工具栏
                url:'type/list',//为datagrid设置数据源
                columns:[[{ //编辑datagrid的列
                    title:'序号',
                    field:'id',
                    align:'center',
                    checkbox:true
                },{
                    title: '现有类型名称',
                    field:'name'
                }/*,{
                    title: '现有库存量',
                    field: 'num'
                }*/]]
            });
        });
    </script><%--datagrid--%>
    <script>
        function searchType(){
            var name = $('#name').textbox("getValue");
            $('#datagrid_type').datagrid('load',{
                "name":name,
            });
        }
    </script><%--searchType()--%>
    <script>
        function addType1(){
            $('#dialog_type').dialog("open").dialog("setTitle","新增商品类型");
            clearForm();
        }
        function editProduct1(){
            var row = $('#datagrid_type').datagrid("getSelected");
            if (row){
                $('#dialog_type').dialog("open").dialog("setTitle","编辑商品类型");
                $('#dialog_form').form("load",{
                    "name":row.name
                });
                paramUrl = "type/editType?id=" + row.id ;
            }else
                $.messager.alert('提示', '请选择要修改的类型', 'info');
        }
        function removeProduct1(){
            var row = $('#datagrid_type').datagrid("getSelected");
            if (row){
                $.post('type/deleteType', {
                    id : row.id
                },function (result){
                    if (result.success == "true"){
                        $('#datagrid_type').datagrid("reload");
                        $.messager.show({
                            title:"提示信息",
                            msg:result.message
                        });
                    }else {
                        $.messager.show({
                            title:"提示信息",
                            msg:result.message
                        });
                    }
                },'json');
            }else
                $.messager.alert('提示', '请选择要删除的类型', 'info');
        }
    </script><%--toolbar--%>
    <script>
        function  clearForm(){
            $('#dialog_form').form("clear");
            paramUrl = 'type/addType';
        }
        function saveType(){
            $('#dialog_form').form("submit",{
                url:paramUrl,
                success:function (result){
                    var result1 = eval('('+result+')');
                    if ( result1.success == 'true' ){
                        $('#datagrid_type').datagrid("reload");
                        $('#dialog_type').dialog("close");
                    }
                    $.messager.show({
                        title:"提示信息",
                        msg:result1.message
                    });
                }
            })
        }
    </script><%--dialog--%>
</body>
</html>
